package com.server.llh.llhserverwork.activity.query;

import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lelaohui.net.netmanager.INetRequestManager;
import com.lelaohui.net.netmanager.ServerNetRequestManager;
import com.llh.llhsuppliers.R;
import com.server.llh.llhserverwork.activity.base.LlhBaseActivity;
import com.server.llh.llhserverwork.view.widget.JudgeDate;
import com.server.llh.llhserverwork.view.widget.ScreenInfo;
import com.server.llh.llhserverwork.view.widget.WheelMain;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by ZTF on 2017-06-09.
 */

public class QueryHelpTaskActivity extends LlhBaseActivity {
    @BindView(R.id.titleName)
    TextView titleName;
    @BindView(R.id.main_back)
    ImageButton mainBack;
    @BindView(R.id.leftBtn_RL_title_base)
    RelativeLayout leftBtnRLTitleBase;
    @BindView(R.id.serverName)
    TextView serverName;
    @BindView(R.id.linearLayout1)
    LinearLayout linearLayout1;
    @BindView(R.id.startTime)
    TextView startTime;
    @BindView(R.id.stopTime)
    TextView stopTime;
    @BindView(R.id.queryServer)
    TextView queryServer;
    @BindView(R.id.timeView)
    LinearLayout timeView;
    @BindView(R.id.health_lv)
    ListView healthLv;
    SwipeRefreshLayout swipeContainer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);

        swipeContainer = (SwipeRefreshLayout)this. findViewById(R.id.swipe_container);
        String startTimeStr = startTime.getText().toString();
        String stopTimeStr = stopTime.getText().toString();
        getTask(startTimeStr, stopTimeStr);
        swipeContainer.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

            @Override
            public void onRefresh() {
                String startTimeStr = startTime.getText().toString();
                String stopTimeStr = stopTime.getText().toString();
                getTask(startTimeStr, stopTimeStr);
            }
        });

    }

    private void getTask(String startTimeStr, String stopTimeStr) {
    }

    @OnClick({R.id.main_back, R.id.startTime, R.id.stopTime, R.id.queryServer})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.main_back:
                break;
            case R.id.startTime:
                break;
            case R.id.stopTime:
                break;
            case R.id.queryServer:
                break;
        }
    }

    WheelMain wheelMain;
    @SuppressLint("SimpleDateFormat")
    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");

    public void showTime(final TextView view) {

        LayoutInflater inflater = LayoutInflater
                .from(QueryHelpTaskActivity.this);
        final View timepickerview = inflater.inflate(R.layout.timepicker, null);
        ScreenInfo screenInfo = new ScreenInfo(QueryHelpTaskActivity.this);
        wheelMain = new WheelMain(timepickerview);
        wheelMain.screenheight = screenInfo.getHeight();
        String time = view.getText().toString();
        Calendar calendar = Calendar.getInstance();
        if (JudgeDate.isDate(time, "yyyy-MM-dd")) {
            try {
                calendar.setTime(dateFormat.parse(time));
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
        int year = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH);
        int day = calendar.get(Calendar.DAY_OF_MONTH);
        wheelMain.initDateTimePicker(year, month, day);
        new AlertDialog.Builder(QueryHelpTaskActivity.this).setTitle("选择时间")
                .setView(timepickerview)
                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        view.setText(wheelMain.getTime());
                    }
                })
                .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                    }
                }).show();

    }
    @Override
    public void showProgress() {
        try{
            showProgress(QueryHelpTaskActivity.this);
        }catch (Exception e){

        }
    }

    @Override
    protected INetRequestManager getRequestManager() {
        return ServerNetRequestManager.getInstance();
    }

    @Override
    public void hideProgress() {
        try{
            closeProgress();
        }catch (Exception e){

        }
    }

    @Override
    protected int getlayout() {
        return R.layout.activity_health_task_all;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void doBasess() {

    }

}
